package com.rla.controller;

import java.util.List;
import java.util.Arrays;

import com.rla.common.annotation.Anonymous;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.rla.common.annotation.RepeatSubmit;
import com.rla.common.annotation.Log;
import com.rla.common.core.controller.BaseController;
import com.rla.common.core.domain.PageQuery;
import com.rla.common.core.domain.R;
import com.rla.common.utils.validate.AddGroup;
import com.rla.common.utils.validate.EditGroup;
import com.rla.common.enums.BusinessType;
import com.rla.common.utils.poi.ExcelUtil;
import com.rla.domain.vo.BaseNewsInformationVo;
import com.rla.domain.bo.BaseNewsInformationBo;
import com.rla.service.IBaseNewsInformationService;
import com.rla.common.core.page.TableDataInfo;

/**
 * 健康科普
 *
 * @author rla
 * @date 2025-08-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/rla/information")
public class BaseNewsInformationController extends BaseController {

    private final IBaseNewsInformationService iBaseNewsInformationService;

    /**
     * 查询健康科普列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo<BaseNewsInformationVo> list(BaseNewsInformationBo bo, PageQuery pageQuery) {
        return iBaseNewsInformationService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出健康科普列表
     */
    @Log(title = "健康科普", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(BaseNewsInformationBo bo, HttpServletResponse response) {
        List<BaseNewsInformationVo> list = iBaseNewsInformationService.queryList(bo);
        ExcelUtil.exportExcel(list, "健康科普", BaseNewsInformationVo.class, response);
    }

    /**
     * 获取健康科普详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<BaseNewsInformationVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iBaseNewsInformationService.queryById(id));
    }

    /**
     * 新增健康科普
     */
    @Log(title = "健康科普", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody BaseNewsInformationBo bo) {
        return toAjax(iBaseNewsInformationService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改健康科普
     */
    @Log(title = "健康科普", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody BaseNewsInformationBo bo) {
        return toAjax(iBaseNewsInformationService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除健康科普
     *
     * @param ids 主键串
     */
    @Log(title = "健康科普", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iBaseNewsInformationService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
